using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Hermes.Framework.FileSystem
{
    public class FileSystemUtils
    {
        public static string GetRelativePath(string sourceFile)
        {
            if (sourceFile.StartsWith("."))
            {
                return Directory.GetCurrentDirectory() + sourceFile.Substring(1);
            }
            return sourceFile;
        }

        public static bool IsLocalFileSystem(string url)
        {
            return url.StartsWith("file://");
        }

        public static bool IsFileTransferProtocol(string url)
        {
            return url.StartsWith("ftp://");
        }

        public static string GetProtocol(string url)
        {
            int colon = url.IndexOf(':');
            string protocol = url.Substring(0, colon);
            return protocol;
        }

        public static string GetFileName(string url)
        {
            int colon = url.IndexOf(':');
            return url.Substring(colon + 3);
        }

        public static string GetDirectoryName(string url)
        {
            int slash = url.LastIndexOf('/');
            return url.Substring(0, slash);
        }
    }
}
